﻿using System.Collections.Generic;
using System.Linq;

namespace ZQNB.BaseLib.UI.Models
{
    #region 首页布局定制实现
    public class Layout
    {
        public Layout()
        {
            this.Rows = new List<Row>();
        }

        public virtual string AppName { get; set; }

        public virtual string Name { get; set; }

        public virtual IList<Row> Rows { get; set; }

        public virtual void AddRow(Row row)
        {
            row.Layout = this;
            row.ItemOrder = Rows.Count == 0
                ? 0
                : Rows.OrderByDescending(x => x.ItemOrder).Select(x => x.ItemOrder).FirstOrDefault() + 1;
            Rows.Add(row);
        }
    }

    public class Row 
    {
        public Row()
        {
            this.Zones = new List<Zone>();
        }

        /// <summary>
        /// Header, Footer, Content
        /// </summary>
        public virtual string Category { get; set; }

        public virtual IList<Zone> Zones { get; set; }

        public virtual Layout Layout { get; set; }

        public virtual void AddZone(Zone zone)
        {
            zone.Row = this;
            zone.ItemOrder = Zones.Count == 0
               ? 0
               : Zones.OrderByDescending(x => x.ItemOrder).Select(x => x.ItemOrder).FirstOrDefault() + 1;
            this.Zones.Add(zone);
        }
        public virtual int ItemOrder { get; set; }
    }

    public class Zone
    {
        public Zone()
        {
            this.Widgets = new List<Widget>();
        }
        /// <summary>
        /// 所占列数，最大12
        /// </summary>
        public virtual int Span { get; set; }

        public virtual string ZoneName { get; set; }

        public virtual int minHeight { get; set; }

        public virtual IList<Widget> Widgets { get; set; }

        public virtual Row Row { get; set; }

        public virtual void AddWidget(Widget widget)
        {
            widget.Zone = this;
            widget.ItemOrder = Widgets.Count == 0
                ? 0
                : Widgets.OrderByDescending(x => x.ItemOrder).Select(x => x.ItemOrder).FirstOrDefault() + 1;

            this.Widgets.Add(widget);
        }

        public virtual int ItemOrder { get; set; }
    }
    
    public class Widget
    {
        public virtual string Name { get; set; }
        public virtual string PartialViewName { get; set; }

        public virtual Zone Zone { get; set; }
        public virtual int ItemOrder { get; set; }
    }
    #endregion
}
